package com.itbour.web.tag.component;

import java.io.IOException;
import java.io.Writer;

import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.components.Component;

import com.itbour.helper.WebHelper;
import com.opensymphony.xwork2.util.ValueStack;

/**
 * copyright   pirate alliance team 2014
 * @author     xuwei
 *
 */
public class SysImageComponent extends Component
{
	/**
	 * 图像路径
	 */
	private String imagePath;

	private String width;

	private String height;

	public SysImageComponent(ValueStack stack)
	{
		super(stack);
	}

	@Override
	public boolean end(Writer writer, String body)
	{
		try
		{
			writer.write("<img src=\"");
			writer.write(WebHelper.getRequest().getContextPath());
			writer.write("/servlet/imageload?PATH=");
			writer.write(imagePath);
			writer.write("\" ");
			if(StringUtils.isNotEmpty(height))
			{
				writer.write("height=\"");
				writer.write(height);
				writer.write("\" ");
			}
			if(StringUtils.isNotEmpty(width))
			{
				writer.write("width=\"");
				writer.write(width);
				writer.write("\" ");
			}
			writer.write(" />");
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
		return super.end(writer, body);
	}

	public String getImagePath()
	{
		return imagePath;
	}

	public void setImagePath(String imagePath)
	{
		this.imagePath = imagePath;
	}

	/**
	 * @return the width
	 */
	public String getWidth()
	{
		return width;
	}

	/**
	 * @param width the width to set
	 */
	public void setWidth(String width)
	{
		this.width = width;
	}

	/**
	 * @return the height
	 */
	public String getHeight()
	{
		return height;
	}

	/**
	 * @param height the height to set
	 */
	public void setHeight(String height)
	{
		this.height = height;
	}

}
